package guoanmaker.operator.business.service;

import guoanmaker.operator.business.model.OperatorHotwords;
import guoanmaker.operator.business.repository.OperatorHotwordsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

/**
 *  
 *
 * @author huZhaoyu 
 * @ClassName: OperatorHotwordsService
 * @Description: OperatorHotwordsService
 * @date 2017/6/27
 */
@Service
public class OperatorHotwordsService implements OperatorHotwordsServiceInterface{
    private final OperatorHotwordsRepository operatorHotwordsRepository;

    @Autowired
    public OperatorHotwordsService(OperatorHotwordsRepository operatorHotwordsRepository) {
        this.operatorHotwordsRepository = operatorHotwordsRepository;
    }

    /** 
     * @Title: saveHotwords 
     * @Description: 新增/修改 热词
     * @param
     * @return OperatorHotwords
     * @throws 
     */
    @Override
    @Transactional
    public OperatorHotwords saveHotwords(OperatorHotwords operatorHotwords) {
        return operatorHotwordsRepository.save(operatorHotwords);
    }

    /** 
     * @Title: getAllHotwords
     * @Description: 获取全部热词
     * @param
     * @return List<OperatorHotwords>
     * @throws 
     */
    @Override
    public List<OperatorHotwords> getAllHotwords() {
    	
        return operatorHotwordsRepository.findAll();
    }

    /** 
     * @Title: getAllHotwordsByPage
     * @Description: 获取全部热词并分页
     * @param
     * @return Page<OperatorHotwords>
     * @throws 
     */
    @Override
    public Page<OperatorHotwords> getAllHotwordsByPage(Integer page, Integer size) {
        Pageable pageable = new PageRequest(page, size);
        return operatorHotwordsRepository.findAll(pageable);
    }

    /** 
     * @Title: deleteHotwordById
     * @Description: 根据ID删除热词
     * @param
     * @return void
     * @throws 
     */
    @Override
    @Transactional
    public void deleteHotwordById(String id) {
        operatorHotwordsRepository.delete(id);
    }

    /** 
     * @Title: getHotwordById
     * @Description: 根据ID查询热词
     * @param
     * @return OperatorHotwords
     * @throws 
     */
    @Override
    public OperatorHotwords getHotwordById(String id) {
        return operatorHotwordsRepository.findOne(id);
    }

	@Override
	public List<OperatorHotwords> getAllHotwordsByCityCodeTwo(String cityCode) {
		// TODO Auto-generated method stub
		return operatorHotwordsRepository.findByCityCodetwo(cityCode);
	}

	@Override
	public OperatorHotwords getAllHotwordsByCityCodeOne(String cityCode) {
		// TODO Auto-generated method stub
		return operatorHotwordsRepository.findByCityCodeOne(cityCode);
	}
	
	 @Override
	    public Map getAllHotwordsByCityId(String cityCode) {
		 Map<String, Object> reMap=new HashMap<String, Object>();
		 OperatorHotwords hot=operatorHotwordsRepository.findByCityCodeOne(cityCode);
		 List<OperatorHotwords> hots= operatorHotwordsRepository.findByCityCodetwo(cityCode);
		 reMap.put("hot", hot);
		 reMap.put("hots", hots);
	        return reMap;
	    }

	@Override
	public List<OperatorHotwords> getAllPcHotwordsByCityCodeTwo(String cityCode) {
		// TODO Auto-generated method stub
		return operatorHotwordsRepository.findPcByCityCodetwo(cityCode);
	}

	@Override
	public OperatorHotwords getAllPcHotwordsByCityCodeOne(String cityCode) {
		// TODO Auto-generated method stub
		return operatorHotwordsRepository.findPcByCityCodeOne(cityCode);
	}
	
	
	 @Override
	    public Map getAllHotwordsByCityIdPc(String cityCode) {
		 Map<String, Object> reMap=new HashMap<String, Object>();
		 OperatorHotwords hot=operatorHotwordsRepository.findPcByCityCodeOne(cityCode);
		 List<OperatorHotwords> hots= operatorHotwordsRepository.findPcByCityCodetwo(cityCode);
		 reMap.put("hot", hot);
		 reMap.put("hots", hots);
	        return reMap;
	    }

}
